package cn.wk.libs4a.view;

import cn.wk.libs4a.R;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

/**
 * 创建Dialog的工厂类
 */
public class DialogFactory {
	
	
	
	/**
	 * 创建Dialog
	 * @return
	 */
	public static void create(Context context,String title,String message,String text0,String text1,final OnCheckClickListener listener){
		LayoutInflater mLayoutInflater = LayoutInflater.from(context);
		
		final Dialog mDialog = new AlertDialog.Builder(context).create();
		mDialog.show();

		View view = mLayoutInflater.inflate(R.layout.dialog_diy_lay, null);
		TextView tv0 = ((TextView)view.findViewById(R.id.tv_ok));
		TextView tv1 = ((TextView)view.findViewById(R.id.tv_cancel));
		((TextView)view.findViewById(R.id.tv_title)).setText(title);
		((TextView)view.findViewById(R.id.tv_message)).setText(message);
		tv0.setText(text0);
		tv1.setText(text1);
		tv0.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				mDialog.dismiss();
				listener.check0();
			}
		});
		tv1.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				mDialog.dismiss();
				listener.check1();
			}
		});
		mDialog.setContentView(view);
	}
	/**
	 * 选中某个按钮的执行方法
	 */
	public interface OnCheckClickListener{
		/**
		 * 第一个按钮事件
		 */
		public void check0();
		/**
		 * 第二个按钮事件
		 */
		public void check1();
	}

}
